package com.chilly.other.thread;

public class ThreadDaemon extends Thread {

    public ThreadDaemon(String name) {
        super(name);
    }

    @Override
    public void run() {
        while (true) {
            System.out.println(Thread.currentThread().getName() + "线程运行了。。。");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Thread t1 = new ThreadDaemon("线程一");
        Thread t2 = new ThreadDaemon("线程二");
        //设置为守护线程
        t1.setDaemon(true);
        t2.setDaemon(true);
        //启动线程
        t1.start();
        t2.start();
        //主线程2s后退出
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}